﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using BusinessLogicLibrary;
using entities;

namespace ServiceLibrary
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class InternalService : IInternalService
    {
        private readonly BookingModule _booking;
        private readonly CustomerModule _customer;
        private readonly RoomModule _room;
        private readonly SearchModule _search;

        public InternalService()
        {
            _booking = new BookingModule();
            _customer = new CustomerModule();
            _room = new RoomModule();
            _search = new SearchModule();
        }

        #region"CUSTOMER Management"

        public List<Customer> CusReadAll()
        {
            return _customer.ReadAllCustomer();
        }

        public string CusAdd(string pIdentityNumber, string pCustomerName, string pCustomerPhone, string pCustomerEmail,
                             bool pCustomerSex, out string account)
        {
            return _customer.CreateCustomer(pIdentityNumber, pCustomerName, pCustomerPhone, pCustomerEmail,
                                            pCustomerSex, out account);
        }

        public string CusModify(int pId, string pIdentityNumber, string pCustomerName, string pCustomerPhone,
                                string pCustomerEmail, bool pCustomerSex)
        {
            return _customer.EditCustomer(pId, pIdentityNumber, pCustomerName, pCustomerPhone, pCustomerEmail,
                                          pCustomerSex);
        }
        
        public List<Customer> FindCustomerByName(string pCustomerName)
        {
            return _customer.FindCustomerByName(pCustomerName);
        }

        public Customer FindCustomerByAccount(string pCustomerAccount)
        {
            return _customer.FindCustomerByAccount(pCustomerAccount);
        }

        public Customer FindCustomerByID(int pId)
        {
            return _customer.FindCustomerByID(pId);
        }

        public Customer FindCustomerByEmail(string pEmail)
        {
            return _customer.FindExtUserByEmail(pEmail);
        }

        public bool CusEmailCheck(string email)
        {
            return _customer.CustomerEmailCheck(email);
        }

        public bool CusIdCheck(string id)
        {
            return _customer.CustomerIdCheck(id);
        }

        #endregion

        #region "SEARCH Room for Booking"

        public List<vRoomInfo> SearchRoom(DateTime inDate, DateTime outDate, int roomTypeId, int minPrice, int maxPrice,
                                          bool view, bool bath, bool balcony)
        {
            return _search.SearchRoom(inDate, outDate, roomTypeId, minPrice, maxPrice, view, bath, balcony);
        }

        #endregion

        #region "Booking Management"

        public string BookAdd(int pCustomerID, List<int> pRoomID, DateTime pCheckInDate, DateTime pCheckOutDate)
        {
            return _booking.CreateBooking(pCustomerID, pRoomID, pCheckInDate, pCheckOutDate);
        }

        public string BookRemove(int bookingId)
        {
            return _booking.DeleteBooking(bookingId);
        }

        public List<Booking> BookGetByCusId(int Id)
        {
            return _booking.GetBookingByCustomerId(Id);
        }

        #endregion

        #region "ROOM Management"

        public List<RoomType> RoTyGet()
        {
            return _room.GetRoomType();
        }

        #endregion

        #region "CHECKIN Management"

        public string CheckInRemove(int checkinId)
        {
            throw new NotImplementedException();
        }

        public CheckIn CheckInGetById(int checkinId)
        {
            throw new NotImplementedException();
        }

        public List<CheckIn> CheckInIncome()
        {
            throw new NotImplementedException();
        }

        public List<CheckIn> CheckInGetByBookingId(int bookingId)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
    

    [ServiceContract]
    public interface IInternalService
    {
        #region CUSTOMER Management

        [OperationContract]
        List<Customer> CusReadAll();

        [OperationContract]
        string CusAdd(string pIdentityNumber, string pCustomerName, string pCustomerPhone, string pCustomerEmail,
                      bool pCustomerSex, out string account);

        [OperationContract]
        string CusModify(int pId, string pIdentityNumber, string pCustomerName, string pCustomerPhone,
                         string pCustomerEmail, bool pCustomerSex);

        [OperationContract]
        List<Customer> FindCustomerByName(string pCustomerName);

        [OperationContract]
        Customer FindCustomerByAccount(string pCustomerAccount);

        [OperationContract]
        Customer FindCustomerByID(int pId);

        [OperationContract]
        Customer FindCustomerByEmail(string pEmail);

        [OperationContract]
        bool CusEmailCheck(string email);

        [OperationContract]
        bool CusIdCheck(string id);

        #endregion

        #region "SEARCH Room for Booking"

        [OperationContract]
        List<vRoomInfo> SearchRoom(DateTime inDate, DateTime outDate, int roomTypeId, int minPrice, int maxPrice,
                                   bool view, bool bath, bool balcony);

        #endregion

        #region "Booking Management"

        [OperationContract]
        string BookAdd(int pCustomerID, List<int> pRoomID, DateTime pCheckInDate, DateTime pCheckOutDate);

        [OperationContract]
        string BookRemove(int bookingId);

        [OperationContract]
        List<Booking> BookGetByCusId(int Id);

        #endregion

        #region "ROOM Management"

        [OperationContract]
        List<RoomType> RoTyGet();

        #endregion

        #region "CHECKIN Management"

        [OperationContract]
        string CheckInRemove(int checkinId);

        [OperationContract]
        CheckIn CheckInGetById(int checkinId);

        [OperationContract]
        List<CheckIn> CheckInIncome();

        [OperationContract]
        List<CheckIn> CheckInGetByBookingId(int bookingId);

        #endregion
    }
}